import React from 'react'
import "./style.scss"
import { userLogin } from '../../api';
import { useNavigate } from 'react-router-dom';
import { Form, Input, Button, message } from 'antd';
function Index() {
    const location=useNavigate()
    const onFinish = async(values: any) => {
        console.log(values)
        const resp=await userLogin(values)
        console.log(resp.data)
        const {mes,code}=resp.data
        if(code===200){
            message.success(mes)
            localStorage.setItem('token','张三')
            location('/')
        }else{
            message.error(mes)
        }
    };
    return (
        <div className="loginWrap">
            <Form
                name="basic"
                labelCol={{ span: 8 }}
                wrapperCol={{ span: 16 }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                autoComplete="off"
            >
                <Form.Item
                    label="用户名"
                    name="username"
                    rules={[{ required: true, message: '请输入用户名' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="密码"
                    name="password"
                    rules={[{ required: true, message: '请输入密码' }]}
                >
                    <Input.Password />
                </Form.Item>
                <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                    <Button type="primary" htmlType="submit">
                        登录
                    </Button>
                </Form.Item>
            </Form>
        </div>
    )
}

export default Index
